function [data_type,  ini_file, fnames, aux_files ] = get_data_type( ini_file, fnames, aux_files)
% get_data_type - find data type (file type)
%   Determines if raw data file type is bin or tif

if exist(ini_file, 'file') == 0
    dash = max(regexp(ini_file,'_'));
    ini_file=[ini_file(1:dash-1) '.ini'];
end

if (exist(ini_file, 'file') == 2)
    try
        data_type =readini(ini_file,'data.type');
    catch
        data_type='bin'; % default bin
    end
    
    if strcmp(data_type, 'tiff') 
        ppath=pwd;
        [pathstr, ~, ~] = fileparts(ini_file);
        cd(pathstr);
        for ind = 1:length(fnames)
            dash = max(regexp(fnames{ind},'_'));
            fnames{ind} = fnames{ind}(1:dash);
            stackdirs   = dir([ fnames{ind} '*']);
            if length(stackdirs)>1
                disp(['Error: multiple matches for '  fnames{ind}])
                return
            else
                fnames{ind}= stackdirs.name;
            end
            
        end
        cd(ppath);
        aux_files={};
    end
    disp(['TIFF stacks,  ' num2str(length(fnames)), ' directories found' ]);
    
else
    disp('No configuration file found. Aborting');
    return  
end 

end

